import request from '@/utils/request'

// 获取订单列表
export function getOrderList(params) {
  return request({
    url: '/api/orders',
    method: 'get',
    params
  })
}

// 获取订单详情
export function getOrderDetail(id) {
  return request({
    url: `/api/orders/${id}`,
    method: 'get'
  })
}

// 创建订单
export function createOrder(data) {
  return request({
    url: '/api/orders',
    method: 'post',
    data
  })
}

// 从购物车创建订单
export function createOrderFromCart(data) {
  return request({
    url: '/api/orders/cart',
    method: 'post',
    data
  })
}

// 更新订单状态
export function updateOrderStatus(id, status) {
  return request({
    url: `/api/orders/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 取消订单
export function cancelOrder(id) {
  return request({
    url: `/api/orders/${id}/cancel`,
    method: 'post'
  })
}

// 支付订单
export function payOrder(id, paymentMethod) {
  return request({
    url: `/api/orders/${id}/pay`,
    method: 'post',
    data: { paymentMethod }
  })
}

// 确认收货
export function confirmReceive(id) {
  return request({
    url: `/api/orders/${id}/confirm`,
    method: 'post'
  })
}

// 获取我的订单列表
export function getMyOrders(params) {
  return request({
    url: '/api/orders/my',
    method: 'get',
    params
  })
}

// 删除订单
export function deleteOrder(id) {
  return request({
    url: `/api/orders/${id}`,
    method: 'delete'
  })
} 